package com.example.demoofimagedownloadapp.view.utils;

import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.example.demoofimagedownloadapp.bean.DataBean;
import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.holder.BannerImageHolder;

import java.util.List;

/**
 * @author ts
 */
public class ImageAdapter extends BannerAdapter<DataBean, BannerImageHolder> {

    private static final String TAG = ImageAdapter.class.getName();

    public ImageAdapter(List<DataBean> mDataList) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDataList);
    }

    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public BannerImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerImageHolder(imageView);
    }

    @Override
    public void onBindView(BannerImageHolder holder, DataBean data, int position, int size) {
        holder.imageView.setImageBitmap(data.getAlbumArt());
        Log.d(TAG, "onBindView: "+data.getSongName()+"/"+data.getAlbumArt());
    }


}
